﻿using System;
using Microsoft.Xna.Framework;

/*  a delegate that adds an event listener to a load rom command that listens for the rom loader to complete 
 *  http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
 *  
 * Gareth Williams
 */

namespace VuzixSample.controller.snes
{
    class RomLoadCompleteListener
    {
        private LoadRomCommand command;
        private RomParser parser;

        public RomLoadCompleteListener(LoadRomCommand command, RomParser parser)
        {
            this.command = command;
            this.parser = parser;

            command.romLoaded += new EventHandler(this.handleCommandChanged);
        }
        private void handleCommandChanged(object Sender, EventArgs e)
        {
            //assign rom header to context of window
            parser.rom = (e as RomLoadedArgs).rom;
        }

        public void Detach()
        {
            command.romLoaded -= new EventHandler(this.handleCommandChanged);
            command = null;
        }
    }
}
